﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Windows.Controls.Primitives;
using Microsoft.Windows.Controls;

namespace WpfApplicationExperimental
{
    /// <summary>
    /// Interaction logic for DocumentsMainDataGridViewControl.xaml
    /// </summary>
    public partial class DocumentsMainDataGridViewControl : UserControl
    {
        public static readonly RoutedEvent TapEvent = EventManager.RegisterRoutedEvent(
    "Tap", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(DataGridComboBoxColumn ));

        public event RoutedEventHandler Tap
        {
            add { AddHandler(TapEvent, value); }
            remove { RemoveHandler(TapEvent, value); }
        }


        public RoutedEventHandler hdkjg;


        public DocumentsMainDataGridViewControl()
        {
            InitializeComponent();
            hdkjg = new RoutedEventHandler(delegate(object j,RoutedEventArgs s) { });
          // SetDocumentsCollection(new DataAccesLayer.DocumentDataProvider().GetDocuments());
            /*
             * 
             * <dg:DataGridComboBoxColumn SelectedValueBinding="{Binding Type}"                                            
                                           SelectedValuePath="id"
                                           DisplayMemberPath="name"
                                           Header="DocumentType"
                                           ItemsSource="{Binding Source={StaticResource documentTypeDataProvider}}">
            

            DataGridComboBoxColumn col = new DataGridComboBoxColumn();
            col.DisplayMemberPath = "name";
            col.ItemsSource = new DataAccesLayer.DocumentDataAccesLayer().GetDocumentTypes();
            col.SelectedValuePath = "id";
            col.SelectedValueBinding = new Binding("Type");
            this.DataGrid_Standard.Columns.Add(col);
             */
     

            //col.sele
       //    foreach (DataGridColumn col in MainDatagridColumnsGenerator.GetDataGridColumns("Document"))
            //   this.DataGrid_Standard.Columns.Add(col);

            this.DataGrid_Standard.ItemsSource = new DataAccesLayer.EQualDataLayerFactory ().GetEmployeeAccesLayer ().GetEmploeesDocumentNotification("2");
        }

        public  void SetDocumentsCollection(IEnumerable <DataAccesLayer .Document > docs)
        {
            this.DataGrid_Standard.ItemsSource = docs;
        }

        private void DataGrid_Standard_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
        {


            if(e.EditAction == DataGridEditAction.Commit )
            try
            {
                object empl = e.Row.Item;
                DataAccesLayer.Employee emplnew = new DataAccesLayer.EQualDataLayerFactory ().GetEmployeeAccesLayer ().GetEmployeeByExample(empl as DataAccesLayer.Employee);
                new DataAccesLayer.EQualDataLayerFactory ().GetEmployeeAccesLayer ().AddEmployeeToBeNotified(2, emplnew.id);
            }
            catch { ((DataGrid)sender).CancelEdit(); }
        
            
        }
    }
}
